from service.note_service import NoteService
from service.comment_srvice import CommentService
from models.note_model import NoteModel
from flask import Blueprint,request
import copy
from service.common_insert_service import CommonInsertSerevice
from service.oss_service import OssService
from service.img_service import ImgService
from service.collection_service import CollectionService


class NoteCommentLikeApplication:

    def get_notes(current,page_size):
        # 获取笔记列表
        note_list = NoteService.get_note_by_current_page(current,page_size)
            
        note_count = NoteService.get_notes_conunt()
        # 构建结果
        result = {'note_info': [],'total': note_count['total']}
        for note in note_list:
            note_id = note['note_id']
            note['slider_images'] = []
            
            # 获取当前笔记的轮播图信息
            slider_images = ImgService.query_note_slider_by_note_id(note_id, current=current, page_size=page_size)
            collection_count = CollectionService.get_collection_count_by_note_id(note_id)
            note['collection_count'] = collection_count['count'] 
            for img in slider_images:
                note['slider_images'].append(img)
            
            result['note_info'].append(note)
        
        return result
    
    def get_all_notes(current,page_size):
        # 获取笔记列表
        note_list = NoteService.get_all_notes(current,page_size)
            
        note_count = NoteService.get_notes_conunt()
        # 构建结果
        result = {'note_info': [],'total': note_count['total']}
        for note in note_list:
            note_id = note['note_id']
            note['slider_images'] = []
            
            # 获取当前笔记的轮播图信息
            slider_images = ImgService.query_note_slider_by_note_id(note_id, current=current, page_size=page_size)
            collection_count = CollectionService.get_collection_count_by_note_id(note_id)
            note['collection_count'] = collection_count['count'] 
            for img in slider_images:
                note['slider_images'].append(img)
            
            result['note_info'].append(note)
        
        return result